/*index*/
function afterAjaxLoadProducts(a, b) {
    if (a.status && 200 == a.status) {
        var c, d = "";
        for (key in a.products) c = a.products[key], d += '<li class="list_product_item"><div class="box_list list_product_item_inner"> <a class="list_product_link box_list_main" rel="nofollow" title="' + c.name + '" href="' + c.url + '" data-role="none" data-ajax="false"><div class="list_product_frame"><div class="list_product_img_block"> <img class="list_product_img _lazyLoadImage" src="' + c.thumb_url + '" alt="' + c.name + '" border="0"/></div><div class="list_product_text_block mb5"><p class="list_product_brand rdstr">' + c.name + '</p><p class="list_product_brand rdstr">' + c.price + "</p>", c.list_price && (d += '<p class="list_product_brand rdstr">' + c.list_price + "</p>"), c.discount && (d += '<p class="list_product_brand rdstr">' + c.discount + "OFF</p>"), d += '</div><span class="arrow"></span>', d += "</div></a></div></li>";
        $("#" + b).append(d)
    }
}

function gotoseach() {
    var a = $("#search_keyword").val();
    "" != a ? window.location.href = "/search/" + a + "?rel=msearch" : $("#search_keyword").focus()
}

function hide_addp_cart_success() {
    document.getElementById("addp_cart_success").style.display = "none"
}

function afterChangeCountry(a, b, c) {
    if (200 == b.status) {
        if (c) var d = $("#" + c);
        else var d = $("#state_id");
        d.find("option").remove();
        for (var e in b.states) d.append('<option value="' + e + '">' + b.states[e] + "</option>")
    } else alert(b.info)
}

function setLocation(a) {
    window.location.href = a
}

function afterDeleteWish(a, b) {
    200 == b.status ? (alert(b.message), $(a).parent().parent().remove()) : alert(b.message)
}

function afterSubscription(a, b) {
    200 == b.status ? (alert("500円OFFのクーポンコード：[share500]コードを保存してください。ご購読のお申し込み完了後、クーポンコードはご利用できます！"), $("#newsletter-email").val(""),window.location.href="http://hassyon.us13.list-manage.com/subscribe?u=2cd9604e53d70c87f31b73155&id=877afcb92f") : (alert(b.message), $("#newsletter-email").val(""))
}
$(function(){
    $("img.lazy").lazyload({
        effect : "fadeIn"
    });
    var mySwiper1 = new Swiper ('.indexBanner_swiper1', { //index banner
        direction: 'horizontal',
        loop: true,
        autoHeight: true,
        autoplay:5000,
        pagination: '.swiper-pagination',
    })
    var mySwiper2 = new Swiper ('.indexTjOne_swiper', { //所有三个布局的轮播
        direction: 'horizontal',
        loop: false,
        slidesPerView:3,
        slidesPerGroup : 3,
        paginationClickable:true,
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',

    })
    var mySwiper4 = new Swiper ('.indexTjThree_swipe', { //所有2个布局的轮播
        direction: 'horizontal',
        autoplay:5000,
        slidesPerView:2,
        slidesPerGroup : 2,
        paginationClickable:true,
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',

    })
    var mySwiper3 = new Swiper ('.product_swiper', {  //product
        direction: 'horizontal',
        loop: true,
        autoplay:5000,
        autoHeight: true,
        pagination: '.swiper-pagination',
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
    })

/**/
    $(".tlHeight").height($(".logoBox").outerHeight());
    $(".topSpecialBanner").height($(".topSpecialBanner").find("img").height())
    /*all checkbox*/
    $(".icheckbox").bind("click",function(){
        if($(this).find("input").is(":checked")){
            $(this).addClass("checked")
        }else{
            $(this).removeClass("checked")
        }
    })
    $(".ulMenu li > div.Header").bind("click",function(){
        var arrow = $(this).find("span.arrow");
        if(arrow.hasClass("bottom")){
            arrow.removeClass("bottom");
        }else{
            arrow.addClass("bottom");
        }
        $(this).parent().find(".Content").slideToggle(500);
    });

    $("a.help_categoryLink").on("click", function(t) {
        t.preventDefault(), $(this).hasClass("_on") ? $(this).removeClass("_on").next(".help_list").slideUp() : $(this).addClass("_on").next(".help_list").slideDown()
    });
    //
    $(".productDetail_content_head").bind("click",function(){
         sliderShow1(this,'.productDetail_content');
    })

    /*productReviews*/
        // productReviews
        $("#productReviews ul.box_list li").click(function () {
          var _index = $(this).index();
          $(this).addClass("active").siblings().removeClass("active");
          $(".flatTab_contents .productReviewsCont").eq(_index).show().siblings().hide();
        });

        $(".reviewFlatTab .reviewFlatTab_item").bind("click",function(){
            $(this).addClass("_selected").siblings().removeClass("_selected");
            var idA = $(this).find("a").attr("href");
            $("._tabArea ._contents").removeClass("_selected");
            $(idA).addClass("_selected");
        })

    /*footer*/
    // $(".footer .footerHead").bind("click",function(){
    //     if($(this).find(".arrow").hasClass("top")){
    //         $(this).find(".arrow").removeClass("top").addClass("bottom");
    //     }else{
    //         $(this).find(".arrow").removeClass("bottom").addClass("top");
    //     }
    //     $(this).next().slideToggle();
    // })
    /**/
    productH();
    productH2();

    // shipping-address  phone
    autoFocus("input[name=phone0]",3,"input[name=phone1]",4,"input[name=phone2]")
    autoFocus("input[name=tel]",3,"input[name=tel1]",3,"input[name=tel2]");
    // checkout
    autoFocus("input[name='Checkout[phonenumber0]']",3,"input[name='Checkout[phonenumber1]']",4,"input[name='Checkout[phonenumber2]']")
    autoFocus("input[name='Checkout[tel]']",3,"input[name='Checkout[tel1]']",3,"input[name='Checkout[tel2]']");
});

function autoFocus(input1,maxLength1,input2,maxLength2,input3){
    $(input1).bind("input propertychange",function(){
        if($(this).val().length == maxLength1){
            $(this).siblings(input2).focus().bind("input propertychange",function(){
                if($(this).val().length == maxLength2){
                    $(this).siblings(input3).focus();
                }
            });
        }
    });
}

function productH(){ //所有列表图片高度控制
    var sq_productH = null;
    var imgAll = $(".product_h img.productImgH");
    if(imgAll != null && imgAll != undefined && imgAll != "" && imgAll.length != 0){
        var img1 = imgAll.eq(0);
        var img = new Image();
        img.src = img1.attr("src");
        var intv = window.setInterval(function(){
                if(img.complete){
                    sq_productH = img1.height();
                    $(".product_h img.productImgH").height(sq_productH);
                    clearInterval(intv);
                }
            }, 50);
    }
}
function productH2(){ //所有列表图片高度控制
    var sq_productH = null;
    var imgAll = $(".productImg img.productImg_H");
    if(imgAll != null && imgAll != undefined && imgAll != "" && imgAll.length != 0){
        var img1 = imgAll.eq(0);
        var img = new Image();
        img.src = img1.attr("src");
        var intv = window.setInterval(function(){
                if(img.complete){
                    sq_productH = img1.height();
                    $(".productImg img.productImg_H").height(sq_productH);
                    clearInterval(intv);
                }
            }, 50);
    }
}
function sliderShow(self) { //首页hot，news
    var showDom = $(self).parents(".cont").find(".sliderShow");
    if(showDom.hasClass("hide")){
        showDom.slideToggle(300).removeClass("hide");
        $(self).removeClass("arrow_b").addClass("arrow_t");
    }else{ 
        $(self).removeClass("arrow_t").addClass("arrow_b");
    }
}
function sliderShow1(self,fatherClas) {
    var showDom = $(self).parents(fatherClas).find(".sliderShow"); //foorter ,cart
    if(!$(self).hasClass("on")){
        showDom.slideToggle(300).removeClass("hide");
        $(self).addClass("on");
    }else{
        showDom.slideToggle(300).addClass("hide");
        $(self).removeClass("on");
    }
}

$(function(){
    window.onscroll = function () {
        /**/
        var top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
        if (top > 300) {
            $(".goTop").show(200);
        } else {
            $(".goTop").hide(200);
        };
    };
})
$(".goTop").click(function(){
    $('body,html').animate({scrollTop:"0px"},100);
});

    $(".muneBtn").bind("click",function(){
        $("#divBox").addClass("box-overflow");
        $(".divBoxOverlay").addClass("push-overlay");
        $(".divBoxOverlay").on('touchmove',function(e){
            e.preventDefault();
        });
        $("#topMenu").addClass("animate-translate");
    });
    $(".divBoxOverlay").click(function(){
        $("#divBox").removeClass("box-overflow");
        $(".divBoxOverlay").removeClass("push-overlay");
        $("#topMenu").removeClass("animate-translate");
    });

/*index end*/

/*product*/
$(".sizeChange .proRadioWrap label").bind("click",function () {
var _index = $(this).index();
  $(this).addClass("labelSelect").siblings().removeClass("labelSelect");
});


$(".input-color label").bind("click",function(){
    if($(this).hasClass("labelSelect")){
        var alt_ = $(this).find("input[type=radio]").next().find("img").attr("alt");
        $("#name-text").text(alt_);
    }
});
$(".input-color label").eq(0).click();
//判断是否有选中加入购物车
$('#falseAddToCartBtn').on('click',function(){
        var inputOptions = document.getElementsByClassName('input-color');
        var inputOptionsLength = inputOptions.length;
        for(var i=0;i<inputOptionsLength;++i){
            var currentOption = inputOptions[i].getElementsByTagName('input');
            var currentOptionLength = currentOption.length;
            var is_selected = false;
            for(var j=0;j<currentOptionLength;j++){
               if(currentOption[j].checked==true){
                 is_selected = true;
               }
            }
            /* how to tips the user to select*/
            if(is_selected==false){
                $(".mask_note").show().delay(2000).hide(0);
                return false;
            }
            /* end tips*/
            
        }
        document.getElementById('TrueAddToCartBtn').click();
});
/*options select end */

/*product end*/

/*checkout*/
$(".henshu-close").bind("click",function(){
    if($(".inputMemberArea").hasClass("hide")){
        $(this).addClass("henshu-open").removeClass("henshu-close");
        $(".inputMemberArea").addClass("show").removeClass("hide");
    }else{
        $(this).addClass("henshu-close").removeClass("henshu-open");
        $(".inputMemberArea").addClass("hide").removeClass("show");
    }
})
$(".newAddressRadio>label").bind("click",function(){
    if($(".showAdd").find("input[type='radio']").is(":checked")){
        $(".inputReceiverArea").addClass("show").removeClass("hide");
    }else{
        $(".inputReceiverArea").addClass("hide").removeClass("show");
    }
})
$(".payment_method>label").bind("click",function(){
    var idx = $(this).index();
    if(idx == 2){
        $(".infoText_").addClass("show").removeClass("hide");
    }else{
        $(".infoText_").addClass("hide").removeClass("show");
    }
})
/*checkout end*/
$("._tabArea .flatTab_nav .flatTab_navList").bind("click",function(){
    var idx = $(this).index();
    $(this).addClass("_selected").siblings().removeClass("_selected");
    $(".flatTab_contents ._contents").eq(idx).addClass("_selected").siblings().removeClass("_selected");
})



$(".top_search").bind("click",function(){
    $(this).parents(".logoBox").find(".headMuneBox").addClass("hide");
    $(".indexSearch").addClass("show").removeClass("hide");
})
$("#cancel-search").bind("click",function(){
    $(".head").find(".logoBox .headMuneBox").removeClass("hide");
    $(".indexSearch").addClass("hide").removeClass("show");
})